//
//  AppDelegate.m
//  ShanghaiShopping
//
//  Created by KDC on 2019/8/22.
//  Copyright © 2019 KDC. All rights reserved.
//

#import "AppDelegate.h"
#import "MainTabBarVC.h"
#import <UMShare/UMShare.h>
#import <UMCommon/UMCommon.h>
#import <WXApi.h>
#import <Bugly/Bugly.h>
#import "WelcomeViewController.h"
//#import <PgyUpdate/PgyUpdateManager.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    // nabigationBar阴影
    [[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[UIImage new]];
    // navigationBar是否半透明模糊处理，此项设置将影响有navigationBar的ViewController的布局
    [UINavigationBar appearance].translucent = NO;
    // 导航栏背景颜色
    [UINavigationBar appearance].barTintColor = [UIColor whiteColor];
    // 导航栏中间标题样式
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                          [UIColor blackColor], NSForegroundColorAttributeName,
                                                          Font_Navigationbar_Title, NSFontAttributeName,
                                                          nil]];
//    --------------------------------------------------------------------------------------
#pragma mark - 腾讯Bugly
    [Bugly startWithAppId:BUGLYID];
    
    
#pragma mark - 友盟分享
    [UMConfigure initWithAppkey:UMengKey channel:@"App Store"];
    [WXApi registerApp:WXAppID universalLink:@""];
    // UMConfigure 通用设置，请参考SDKs集成做统一初始化。
    [self configUSharePlatforms];
    [self confitUShareSettings];
//#pragma mark - 蒲公英监测自动更新
//    [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:DandelionKey];
//    [[PgyUpdateManager sharedPgyManager] checkUpdate];
//
    
    [self gotoTabbarController];
    return YES;
}

- (void)confitUShareSettings {
    /*
     * 打开图片水印
     */
    [UMSocialGlobal shareInstance].isUsingWaterMark = YES;
    [UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
}

- (void)configUSharePlatforms {
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WXAppID appSecret:WXAppSecret redirectURL:@"http://mobile.umeng.com/social"];
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:QQAPPID appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
    
//    [UMSocialUIManager addCustomPlatformWithoutFilted:UMSocialPlatformType_UserDefine_Begin + 1 withPlatformIcon:ImageNamed(@"collect_N") withPlatformName:@"收藏"];
}

//创建tabbarVC
- (void)gotoTabbarController {
    
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    BOOL isNotFirstOpen = [ud boolForKey:IsNotFirstOpen];
    
    if (isNotFirstOpen) {
        MainTabBarVC *vcMainTabbar = [[MainTabBarVC alloc] init];
        self.window.rootViewController = vcMainTabbar;
    } else {
        self.window.rootViewController = [[WelcomeViewController alloc] init];
    }
    [ud setBool:YES forKey:IsNotFirstOpen];
    [ud synchronize];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
